package com.gxa.admin.recycling.controller;

import com.gxa.admin.recycling.service.RecycleOrderService;
import com.gxa.core.recycling.common.JsonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 周志远
 */
@CrossOrigin
@RestController
@Transactional(rollbackFor = {Throwable.class})
@RequestMapping("/recycleOrder")
@Api(tags = "回收预约管理页面接口")
public class RecycleOrderController {
    @Autowired
    RecycleOrderService recycleOrderService;
    @PostMapping("/findByPage")
    @ApiOperation("查询所有订单+分页")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",value = "预约单id",required = false,dataType = "Long"),
            @ApiImplicitParam(name = "provinces",value = "省市区",required = false,dataType = "String"),
            @ApiImplicitParam(name = "comityname",value = "小区名称",required = false,dataType = "String"),
            @ApiImplicitParam(name = "username",value = "预约人姓名",required = false,dataType = "String"),
            @ApiImplicitParam(name = "recyclername",value = "接单人姓名",required = false,dataType = "String"),
            @ApiImplicitParam(name = "state",value = "订单状态",required = false,dataType = "String"),
            @ApiImplicitParam(name = "ordertime",value = "预约时间",required = false,dataType = "String"),
            @ApiImplicitParam(name = "page",value = "页码",required = true,dataType = "Integer"),
            @ApiImplicitParam(name = "size",value = "每页显示数",required = true,dataType = "Integer")

    })
    public Map findByPage(Long id, String comityname, String provinces, String username, String recyclername, String state, String ordertime, Integer page, Integer size){
        List<Map> allByPage = recycleOrderService.findAllByPage(id, comityname, provinces, username, recyclername, state, ordertime, page, size);
        List<Map> allByPage1 = recycleOrderService.findAllByPage(id, comityname, provinces, username, recyclername, state, ordertime, 1, 10000);
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("200");
        jsonResult.setData(allByPage);
        jsonResult.put("count",allByPage1.size());
        return jsonResult.getDataMap();
    }
    @PostMapping("/orderDetail")
    @ApiOperation("查询单个订单（预约单详情页面）")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",value = "预约单id",required = true,dataType = "Long")
    })
    public Map orderDetail(Long id){
        List<Map> byId = recycleOrderService.findById(id);
        System.out.println(byId);
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("200");
        jsonResult.setData(byId);
        return jsonResult.getDataMap();
    }


}
